
<#assign className = table.className>   
<#assign classNameFirstLower =className?uncap_first>   
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${mapperpack}.${className}Mapper">

    <resultMap id="BaseResultMap" type="${basepackage}.${className}">
	<#list table.fileds as column>
        <result column="${column.mysqlName}" javaType="${column.javaFullType}" jdbcType="${column.mysqlType}" property="${column.columnNameFirstLower}"/>
	</#list>
    </resultMap>

	<resultMap id="RelationResultMap" type="${basepackage}.${className}">
		<#list table.fileds as column>
		<result column="${column.mysqlName}" javaType="${column.javaFullType}" jdbcType="${column.mysqlType}" property="${column.columnNameFirstLower}"/>
		</#list>
		<#list table.relationTables as table1>
			<#assign _name1 = (table1.isList>=1)?string(table1.className?uncap_first+"s",table1.className?uncap_first)>
            <collection property="${_name1}" ofType="${basepackage}.${table1.className}" >
				<#list table1.fileds as column>
                    <result column="${table1.name}_${column.mysqlName}" javaType="${column.javaFullType}" jdbcType="${column.mysqlType}" property="${column.columnNameFirstLower}"/>
				</#list>
			</collection>
		</#list>
	</resultMap>

    <select id="selectMyPage" resultMap="RelationResultMap" parameterType="java.lang.Integer" >
		select
	<#assign rsize = table.relationTables?size>
	<#list table.fileds as column>${table.name}.${column.mysqlName}<#if (column_has_next||rsize>0)>,</#if></#list>
	<#list table.relationTables as table1>
	<#list table1.fileds as column>${table1.name}.${column.mysqlName} as ${table1.name}_${column.mysqlName}  <#if (column_has_next||table1_index<(rsize-1))>,</#if> </#list>
	</#list>
		from
        `${table.name}` <#if (rsize>0)>,</#if>
		<#list table.relations as relation1>
        <#if (relation1.reTable ? exists)>
		`${relation1.reTable}`<#if (relation1_has_next||(table.relationTables?size>0))>,</#if>
		</#if>
		</#list>
	<#list table.relationTables as table1>
        `${table1.name}`<#if ((table1_has_next))>,</#if>
	</#list>
		where
		1=1
	<#list table.relations as relation1>
        and
		<#if (relation1.reTable ? exists)>
		${relation1.sourceTable}.${relation1.sourceColumn}=${relation1.reTable}.${relation1.reSourceColumn}
        and
		${relation1.reTable}.${relation1.reTargerColumn}=${relation1.targerTable}.${relation1.targerColumn}
		<#else>
		${relation1.sourceTable}.${relation1.sourceColumn}=${relation1.targerTable}.${relation1.targerColumn}
		</#if>
	</#list>
	${r'${ew.sqlSegment}'}

    </select>
</mapper>

